import { isArray, isObject, isNumber, isString } from '@/utils/is'
const APP_NAME = import.meta.env.VITE_APP_NAME

export const useUNIAPI = () => {
	// 拨打电话
	const callTell = (phone : String) => {
		return new Promise((resolve, reject) => {
			uni.makePhoneCall({
				phoneNumber: phone,
				success: function () { resolve() },
				fail: function () { reject() },
			});
		})
	}
	// 设置系统剪贴板的内容
	const setCopyData = (data : any, toast : boolean = true) => {
		let info : string = ''
		if (isArray(data) || isObject(data)) {
			info = JSON.stringify(data)
		} else if (isNumber(data)) {
			info = data.toString()
		} else if (isString(data)) {
			info = data
		} else {
			info = data.toString()
		}
		return new Promise((resolve, reject) => {
			uni.setClipboardData({
				data: info,
				showToast: toast,
				success: function () { resolve() },
				fail: function () { reject() },
			});
		})
	}
	// 获取系统剪贴板内容
	const getCopyData = () => {
		return new Promise((resolve, reject) => {
			uni.getClipboardData({
				success: function (res) { resolve(res) },
				fail: function (err) { reject(err) },
			});
		})
	}
	// 动态设置当前页面的标题
	const setTitle = (title : string) => {
		uni.setNavigationBarTitle({
			title
		})
	}
	return {
		callTell,
		setCopyData,
		getCopyData,
		setTitle
	}
}